#include "TestCheckBoxForm.h"


TestCheckBoxForm::TestCheckBoxForm() 
	: m_checkBox(1), m_btnAutoCheck(2), m_btnPushLike(3), m_btnThreeState(4) {

	CreatedEvent.Register(this, &TestCheckBoxForm::OnCreated);
}


void TestCheckBoxForm::OnCreated(CreatedEventArgs&) {

	this->SetSize(400, 300);

	m_btnPushLike.Create();
	m_btnPushLike.SetParent(*this);
	m_btnPushLike.SetText(L"Push like");
	m_btnPushLike.SetSize(80, 30);
	m_btnPushLike.SetPosition(0, 0);

	m_btnThreeState.Create();
	m_btnThreeState.SetParent(*this);
	m_btnThreeState.SetText(L"Three state");
	m_btnThreeState.SetSize(80, 30);
	m_btnThreeState.SetPosition(80, 0);

	m_btnAutoCheck.Create();
	m_btnAutoCheck.SetParent(*this);
	m_btnAutoCheck.SetText(L"Auto check");
	m_btnAutoCheck.SetSize(80, 30);
	m_btnAutoCheck.SetPosition(160, 0);

	m_checkBox.Create();
	m_checkBox.SetParent(*this);
	m_checkBox.SetText(L"Check box");
	m_checkBox.SetSize(100, 30);
	m_checkBox.SetPosition(50, 50);

	m_labChecked.Create();
	m_labChecked.SetParent(*this);
	m_labChecked.SetText(L"Unchecked");
	m_labChecked.SetSize(200, 30);
	m_labChecked.SetPosition(0, 90);
}



LRESULT TestCheckBoxForm::WndProc(const WndMsg& msg) {

	switch (msg.Message) {

	case WM_COMMAND:
		if (msg.WParamHigh == BN_CLICKED) {
			if (msg.WParamLow == m_btnAutoCheck.GetID()) {
				m_checkBox.IsAutoCheck( ! m_checkBox.IsAutoCheck());
			}
			else if (msg.WParamLow == m_btnPushLike.GetID()) {
				m_checkBox.IsPushLike( ! m_checkBox.IsPushLike());
			}
			else if (msg.WParamLow == m_btnThreeState.GetID()) {
				m_checkBox.IsThreeState( ! m_checkBox.IsThreeState());
			}
			else if (msg.WParamLow == m_checkBox.GetID()) {

				switch (m_checkBox.GetCheckState()) {

				case CheckState::Checked:
					m_labChecked.SetText(L"Checked");
					break;

				case CheckState::Unchecked:
					m_labChecked.SetText(L"Unchecked");
					break;

				case CheckState::Indeterminate:
					m_labChecked.SetText(L"Indeterminate");
					break;
				}
				
			}
		}

	default:
		break;
	}

	return Form::WndProc(msg);
}